<?php
signcheck(array($uid,$imei,$pt,$appid));

$time_id = $_GET['time_id'];
//echo $time_id;
$te = date('H', time());
$time = date('Ymd', time());

$re = $time . $time_id . '00';
if ($te >= 10 && $te < 13) {
    if (in_array($time_id, array(10, 20, 22))) {
        $time_start = '0';
        if($time_id==20 ||$time_id==22){
           $re = date('Ymd',strtotime('-1 days')). $time_id . '00';
        }
    } else {
        $time_start = '1';
    }
} elseif ($te >= 13 && $te < 15) {
    if (in_array($time_id, array(13, 10, 22))) {
        $time_start = '0';
    if($time_id==22){
           $re = date('Ymd',strtotime('-1 days')). $time_id . '00';
        }    
    } else {
        if($time_id < 13){
            $time_start = '0';
        }else{
            $time_start = '1';
        }
    }
} elseif ($te >= 15 && $te < 20) {
    if (in_array($time_id, array(15, 13, 10))) {
        $time_start = '0';
    } else {
        if($time_id < 15){
            $time_start = '0';
        }else{
            $time_start = '1';
        }
    }
} elseif ($te >= 20 && $te < 22) {
    if (in_array($time_id, array(20, 15, 13))) {
        $time_start = '0';
    } else {
        if($time_id < 20){
            if($time_id == '10'){
                $time_start = '1';
                $re = date('Ymd',strtotime('+1 days')). $time_id . '00';
            }else{
                $time_start = '0';
            }
        }else{
            $time_start = '1';
        }
    }
} elseif ($te >= 22 || $te < 10) {
    if (in_array($time_id, array(22, 20, 15))) {
        $time_start = '0';
    if($te < 10){
        $re = date('Ymd',strtotime('-1 days')). $time_id . '00';    
    }
    } else {
        if($time_id < 22){
            if($time_id == '10' || $time_id == '13'){
                $time_start = '1';
            if($te>=22){
               $re = date('Ymd',strtotime('+1 days')). $time_id . '00';
            }
            }else{
                $time_start = '0';
            }
        }else{
            $time_start = '1';
        }
    }
}
//else{
//    $time_start = '1';
//}

$count = "select count(*) as count from tttj.goods where category = 45 and dstatus = 1 and time_limit_up = '$re' order by id desc";
//echo $count;
//$re_count = getonerecord($count);

$page = $_GET['page']? $_GET['page'] : 0;
$page = $page*10;
$pages = 10;
//$page = $page*$re_count['count'];
//$pages = $re_count['count'];

$sql = "select id,taobao_id,title,pic_url,num,coupon_link,coupon_type,di_type,di_cash,price,reserve_price,goods_link,remain from tttj.goods where category = 45 and dstatus = 1 and time_limit_up = '$re' order by id desc limit $page,$pages";
//echo $sql;
$re = exec_db($sql);
while ($val = mysqli_fetch_assoc($re)) {
    $item['gtbid'] = $val['taobao_id'];
    $item['gname'] = $val['title'];
    $item['gicon'] = $val['pic_url'];
    $item['glink'] = $val['goods_link'] ? $val['goods_link'] : '';
    $item['remain'] = $val['remain'];
    $sql = "select * from tttj.time_limit_stock where goods_id = ".$val['id'];
    $stock = getonerecord($sql);
    $item['stock'] = $stock['stock'];
    $item['gtype'] = $val['coupon_type'];
    $item['di_cash'] = $val['di_cash'];
    $item['gprice'] = $val['price'] - $val['di_cash'];
    $item['gyuan'] = $val['price'];
    $sql = "select stock from tttj.time_limit_stock where goods_id = ".$val['id'];
    $data = getonerecord($sql);
//    $item['remain'] = $data['stock'];
    $item['remain'] = rand(1,100);

    if ($val['coupon_link']) {
        $item['di_type'] = 2;
        $item['clink'] = $val['coupon_link'];
        $item['buy_type'] = 1;
    } else {
        $item['buy_type'] = 1;
        $item['clink'] = '';
        $item['di_type'] = 1;
    }

    $item['goods_id'] = $val['id'];
    $time_goods[] = $item;
}

if(empty($time_goods)){
    $time_goods = array();
}else{
    foreach($time_goods as $k=>$v){
        $sql = "select * from tttj.remind_goods where uid=$uid and goods_id=".$v['goods_id']." and appid=$appid";
        $t_re = getonerecord($sql);
        if($t_re){
            $time_goods[$k]['remind'] = '1';
        }else{
            $time_goods[$k]['remind'] = '0';
        }
    }
}


$goods['time_goods'] = $time_goods;
$goods['time_start'] = $time_start;
$now_time = time();

echo echojson('success', 1, $goods);
?>